package com.java.system.common.entity;

import com.java.system.common.util.IdGen;
import com.java.system.common.validatedGroup.Add;
import com.java.system.common.validatedGroup.Modify;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;


import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.util.Date;

/**
 * @ClassName: BaseEntity
 * @Description:
 * @Version: v1.0.0
 * @Author: greatesky
 * @Date: 2019/9/5 15:14
 * Modification History:
 * Date             Author      Version     Description
 * -------------------------------------------------------------
 * 2019/9/5      greatesky      v1.0.0      创建
 */

@Data
@Accessors(chain = true)
public class BaseEntity {
    @Id
    @Null(message = "{add_id}", groups = {Add.class})
    @NotNull(message = "{modify_id}", groups = {Modify.class})
    private String id;

    private String crtUser;

    private Date crtTime;

    private String crtName;

    private String crtHost;

    private String updUser;

    private Date updTime;

    private String updName;

    private String updHost;

    private Integer delFlag;

    /**
     * 作用：插入之前的操作
     */
    public void preInsert(){
        if (StringUtils.isBlank(this.getId())){
            setId(IdGen.uuid());
        }
        //TODO 设置当前操作用户信息、IP地址信息
        this.crtTime = new Date();
        this.delFlag = 0;
    }

    /**
     * 更新之前的操作
     */
    public void preUpdate(){
        //TODO 设置当前操作用户信息、IP地址信息
        this.updTime = new Date();
    }
}
